﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.Record;
using TyMES.Model;

namespace TyMES.ViewModel.Record.StationLogRecordVMs
{
    public partial class StationLogRecordListVM : BasePagedListVM<StationLogRecord_View, StationLogRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<StationLogRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<StationLogRecord_View>>{
                
                this.MakeGridHeader(x => x.StationLogRecord_Date_Time).SetTitle(@Localizer["Page.日期时间"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_LineCode).SetTitle(@Localizer["Page.产线编号"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_StationCode).SetTitle(@Localizer["Page.工站编号"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_Log).SetTitle(@Localizer["Page.日志信息"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_LogType).SetTitle(@Localizer["Page.日志类型"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.StationLogRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<StationLogRecord_View> GetSearchQuery()
        {
            var query = DC.Set<StationLogRecord>()
                
                .CheckBetween(Searcher.Date_Time?.GetStartTime(), Searcher.Date_Time?.GetEndTime(), x => x.Date_Time, includeMax: false)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.StationCode, x=>x.StationCode)
                .CheckContain(Searcher.Log, x=>x.Log)
                .CheckContain(Searcher.LogType, x=>x.LogType)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new StationLogRecord_View
                {
				    ID = x.ID,
                    
                    StationLogRecord_Date_Time = x.Date_Time,
                    StationLogRecord_LineCode = x.LineCode,
                    StationLogRecord_StationCode = x.StationCode,
                    StationLogRecord_Log = x.Log,
                    StationLogRecord_LogType = x.LogType,
                    StationLogRecord_CreateTime = x.CreateTime,
                    StationLogRecord_UpdateTime = x.UpdateTime,
                    StationLogRecord_CreateBy = x.CreateBy,
                    StationLogRecord_UpdateBy = x.UpdateBy,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

        
    }
    public class StationLogRecord_View: StationLogRecord
    {
        
        public DateTime? StationLogRecord_Date_Time { get; set; }
        public string StationLogRecord_LineCode { get; set; }
        public string StationLogRecord_StationCode { get; set; }
        public string StationLogRecord_Log { get; set; }
        public string StationLogRecord_LogType { get; set; }
        public DateTime? StationLogRecord_CreateTime { get; set; }
        public DateTime? StationLogRecord_UpdateTime { get; set; }
        public string StationLogRecord_CreateBy { get; set; }
        public string StationLogRecord_UpdateBy { get; set; }

    }

}